import http from "../utils/http/http";

// 获取图表数据
export const getRecentChartData = (sensCode) => {
    return http.get('/admin/actData/recentChartData/', { sensCode });
};
// 获取表格数据
export const getRecentTableData = (page, size, sensCode) => {
    return http.get('/admin/actData/recentTableData', { page, size, sensCode});
};
// 获取筛选后的图表数据
export const getFilteredChartData = (startTime, endTime, sensCode) => {
    return http.get('/admin/actData/filteredChartData', {
        startTime: formatDateTime(startTime),
        endTime: formatDateTime(endTime),
        sensCode: sensCode
    });
};
// 获取筛选后的表格数据
export const getFilteredTableData = (startTime, endTime, page, size, sensCode) => {
    return http.get('/admin/actData/filteredTableData', {
        startTime: formatDateTime(startTime),
        endTime: formatDateTime(endTime),
        page: page,
        size: size,
        sensCode: sensCode
    });
};
// 获取最新监测开关状态
export const getLatestStatus = () => {
    return http.get('/admin/actData/latestStatus');
};

function formatDateTime(dateTime) {
    const date = new Date(dateTime);
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
